home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / mcomm557.zip / COMM.HPP < prev    next >
C/C++ Source or Header  |  1993-09-11  |  18KB  |  382 lines

  1.  
  2. /////////////////////////////////////////////////////////////////////////////
  3. //                                                                         //
  4. //  COMM.HPP -- header file for C++ programs using MCOMM async routines.   //
  5. //    Zortech C++ 2.0, Turbo C++ 1.00 version.                             //
  6. //                                                                         //
  7. //    Mike Dumdei,  6 Holly Lane,  Texarkana TX  75503    (c) 1989,1990    //
  8. //                                                                         //
  9. /////////////////////////////////////////////////////////////////////////////
  10.  
  11. #if !defined(COMM_HPP)
  12. #define COMM_HPP
  13.  
  14. #ifndef MCOMM
  15.   #define _C_ cdecl
  16.   #define _V_ volatile
  17.   #define _F_ far
  18.   #if (__TURBOC__ && __HUGE__)
  19.     #define _N_
  20.   #else
  21.     #define _N_ near
  22.   #endif
  23.   #define MCOMM
  24. #endif
  25.  
  26. //////////////////////////////////////////////
  27. //  Return codes                            //
  28. //////////////////////////////////////////////
  29. #ifndef __ZTC__
  30.   #define   R_OK           0x0000
  31. #endif
  32. #define     R_NOMEM        0x0001
  33. #define     R_BAUDERR      0x0002
  34. #define     R_PARITYERR    0x0004
  35. #define     R_DTABITERR    0x0008
  36. #define     R_STPBITERR    0x0010
  37. #define     R_IRQUSED      0x0020
  38. #define     R_VCTRUSED     0x0040
  39. #define     R_NOPORT       0x0080
  40. #define     R_PORTUSED     0x0100
  41. #define     R_UARTERR      0x0200
  42.  
  43. #define     R_TXERR        (-1)
  44.  
  45. //////////////////////////////////////////////
  46. //  Interrupt bit masks                     //
  47. //////////////////////////////////////////////
  48. #define     IRQ3           0x08
  49. #define     IRQ4           0x10
  50.  
  51. //////////////////////////////////////////////
  52. //  Vector numbers                          //
  53. //////////////////////////////////////////////
  54. #define     VCTR3          0x0b
  55. #define     VCTR4          0x0c
  56.  
  57. //////////////////////////////////////////////
  58. //  Standard Comm Ports                     //
  59. //   Note - due to the ability to overload  //
  60. //   the open call, COM1 and COM2 are def-  //
  61. //   ined differently in the C++ version.   //
  62. //////////////////////////////////////////////
  63. #define     COM1        0
  64. #define     COM2        1
  65.  
  66. //////////////////////////////////////////////
  67. //  Defines for async_regs function         //
  68. //////////////////////////////////////////////
  69. #define     RXreg       0
  70. #define     TXreg       0
  71. #define     IERreg      1
  72. #define     IIDreg      2
  73. #define     FCRreg      2
  74. #define     LCRreg      3
  75. #define     MCRreg      4
  76. #define     LSRreg      5
  77. #define     MSRreg      6
  78. #define     LObaud      0
  79. #define     HIbaud      1
  80.  
  81. //////////////////////////////////////////////
  82. //  Miscellaneous bit masks                 //
  83. //////////////////////////////////////////////
  84. #define     B_DTR        0x0001
  85. #define     B_RTS        0x0002
  86.  
  87. /////////////////////////////////////////////////////////////////////////
  88. //  Status bit masks                                                   //
  89. /////////////////////////////////////////////////////////////////////////
  90.   //  S T A T 2  //
  91. #define     B_XUSE       0x0001   // using XON/XOFF protocol bit
  92. #define     B_XRXD       0x0002   // XOFF received bit
  93. #define     B_XSENT      0x0004   // XOFF sent bit
  94. #define     B_TXEMPTY    0x0008   // nothing to transmit bit
  95. #define     B_CTS        0x0010   // clear to send bit
  96. #define     B_DSR        0x0020   // data set ready bit
  97. #define     B_FLOWHALT   0x0040   // flow halt indicator bit
  98. #define     B_MNTR_CD    0x0080   // monitor CD bit
  99.  
  100.   //  S T A T 1  //
  101. #define     B_RXOVF      0x0100   // rx buffer overflow indic bit
  102. #define     B_OVERRUN    0x0200   // char overrun error bit
  103. #define     B_PARITY     0x0400   // parity error bit
  104. #define     B_FRAMING    0x0800   // framing error bit
  105. #define     B_BREAK      0x1000   // line break signal detected
  106. #define     B_THRE       0x2000   // used in interrupt hdlr (always 0)
  107. #define     B_RXEMPTY    0x4000   // rx buffer empty bit
  108. #define     B_CD         0x8000   // carrier detect bit mask
  109.  
  110.   //  S T A T 3  //
  111. #define     B_IGNERR     0x0001   // discard chars with par, frm'g errs
  112. #define     B_16550      0x0002   // 16550 detected
  113. #define     B_FIFO       0x0004   // 16550 FIFOs enabled
  114. #define     B_ORGFIFO    0x0008   // FIFOs were on when port was opened
  115. #define     B_FARBUFFER  0x0010   // using FAR ring buffers
  116. #define     B_XUSET      0x0020   // using XON/XOFF on txmt side bit
  117. #define     B_XUSER      0x0040   // using XON/XOFF on recv side bit
  118. #define     B_XONANY     0x0080   // accept any char for an XON
  119.  
  120.  
  121. /////////////////////////////////////////////////////////////////////////
  122. //                                                                     //
  123. //  A s y n c P o r t   C l a s s                                      //
  124. //                                                                     //
  125. //                    * * *  W A R N I N G  * * *                      //
  126. //     This class must have the port variables byte aligned.  As       //
  127. //     written, ZTC 2.0 will byte align this structure without the     //
  128. //     need to direct it to pack structures.  If you are using         //
  129. //     a different implementation of C++ be sure this data is          //
  130. //     byte aligned by your compiler.                                  //
  131. /////////////////////////////////////////////////////////////////////////
  132.  
  133. class AsyncPort
  134. {
  135.       // port variables
  136.   private:
  137.     int ComBase;          // base port address of for comm port
  138.     char IRQMask;         // mask for IRQ used by this port
  139.     char Vector;          // interrupt vector used by this port
  140.     char BPDSstr[10];     // current baud,parity,data,stop parms
  141.     int RxSize;           // size of receive bufr
  142.     int TxSize;           // size of transmit bufr
  143.     int RingSeg;          // segment of rx/tx bufrs (leave 0 for NEAR)
  144.     int RingOfst;         // offset of rx/tx bufrs, alias TxTop
  145.     int RxTop;            // ptr to begin of rx bufr, alias TxBtm
  146.     int RxBtm;            // ptr to end of rx bufr (end + 1)
  147.     int _V_ TxIn;         // ptr to where next 'put' goes
  148.     int _V_ TxOut;        // ptr to where next tx'd comes from
  149.     int _V_ TxFree;       // remaining tx bufr space
  150.     int _V_ RxIn;         // pointer to where next rx'd goes
  151.     int _V_ RxOut;        // ptr to where next 'get' comes from
  152.     int _V_ RxFree;       // remaining bytes in rx bufr space
  153.     int BaudDvsr;         // baud rate divisor
  154.     int XoffTrip;         // send XOFF when this many bytes left in rxbuf
  155.     int XonTrip;          // send XON when this many bytes left in rxbuf
  156.     int OldVctrOfst;      // OFST address of original interrupt vector
  157.     int OldVctrSeg;       // SEG address of original interrupt vector
  158.     int OldDvsr;          // original value of Baud Divisor Regs
  159.     char _V_ Stat2;       // secondary status byte
  160.     char _V_ Stat1;       // primary status byte
  161.     char _V_ TxStat;      // determines when tx_intrpts need turned on
  162.     char MSRMask;         // slcts bits in MSR montrd for flow cntrl
  163.     char _V_ MSRVal;      // present value of modem status register
  164.     char _V_ Stat3;       // another flag, used for XONANY char
  165.     char PDSinfo;         // parity, # dta bits, # stop bits
  166.     char StripMask;       // mask for high bit stripping
  167.     char XTxRptInit;      // initialization value for XTxRpt below
  168.     char _V_ XTxRpt;      // countdown val befr repeat tx of XOFF
  169.     char _V_ TxImmedChar; // char to be tx'd 1st opportunity
  170.     char HdlrUsed;        // assigned interrupt handler for this port
  171.     char Old8259Msk;      // original 8259 interrupt mask
  172.     char OldLCR;          // original Line Control Reg value
  173.     char OldMCR;          // original Modem Cntrl Reg value
  174.     char OldIER;          // original Interrupt Enable Reg value
  175.     int TxByteCnt;        // number bytes to send per tx interrupt
  176.     char FCRVal;          // FIFO control register data byte
  177.     char IERVal;          // interrupt enable register value
  178.     char _V_ MCRVal;      // modem